package kpi.java_training.testing.education;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Vladislav
 * Date: 13.11.13
 * Time: 10:58
 * To change this template use File | Settings | File Templates.
 */
public class TypeController {
    private List<TypeScore> typeScores;
    public TypeController() {
        typeScores = new ArrayList<TypeScore>();
    }
    private int getTypePlace(TypeScore typeScore) {
        for(int i = 0; i < typeScores.size(); i++) {
            if(typeScores.get(i).getType().equals(typeScore.getType())) {
                return i;
            }
        }
        return -1;
    }
    public double getWinPercent(String type) {
        int place = getTypePlace(type);
        return typeScores.get(place).getWinPercent();
    }
    private int getTypePlace(String type) {
        for(int i = 0; i < typeScores.size(); i++) {
            if(typeScores.get(i).equals(type)) {
                return i;
            }
        }
        return -1;
    }
    public void pushType(TypeScore typeScore) {
        int currentElement = getTypePlace(typeScore);
        if(currentElement != -1) {
            typeScores.get(currentElement).newQuestionAnswered(typeScore);
        } else {
            typeScores.add(typeScore);
        }
    }

    /**
     * returns level of required type
     * @param type
     */

    public int getLevel(String type) {
        int currentElement = getTypePlace(type);
        if(currentElement != -1) {
            return typeScores.get(currentElement).getCurrentLevel();
        }
        return 0;
    }
}
